app.factory("myFactory",function(){
  var students=[
    {
      id:"1",
      name:"lien",
      class:"七班",
      type:"wuli",
      icon:"../../img/maohelaoshu.gif"
    },
    {
      id:"2",
      name:"yalisha",
      class:"七班",
      type:"magi",
      icon:"../../img/maohelaoshu.gif"
    }
  ]

  var service={};
  service.getArtist=function(){
    return students;
  }
  return service;

})

app.controller("demoListController",function($scope,myFactory){
  $scope.add=function(){
    console.log("add");
    $scope.$broadcast("to-demoFormController-add");
  }
  $scope.edit=function($index){

    $scope.$broadcast("to-demoFormController-edit",{data:$scope.students[$index],index:$index});
  }

  $scope.remove=function($index){
    if(window.confirm("确定要删除这条信息？")){
      $scope.students.splice($index,1);
    }
  }
  $scope.$on("to-demoListController-addData-success",function(event,data){
    data.icon="../../img/maohelaoshu.gif";
    data.id=$scope.students.length;
    $scope.students.push(data);
  })
  $scope.$on("to-demoListController-editData-success",function(event,data){
    $scope.students[data.index].class=data.class;
    $scope.students[data.index].name=data.name;
    $scope.students[data.index].type=data.type;
  });
  $scope.students=myFactory.getArtist();

  //$scope.students=[
  //  {
  //    id:"1",
  //    name:"lien",
  //    class:"七班",
  //    type:"wuli",
  //    icon:"../img/maohelaoshu.gif"
  //  },
  //  {
  //    id:"2",
  //    name:"yalisha",
  //    class:"七班",
  //    type:"magi",
  //    icon:"../img/maohelaoshu.gif"
  //  }
  //]
})